﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Gama.Extension
{
    public static partial class HtmlHelperExtensions
    {
        public static HiddenBuilder<TModel> HiddenEx<TModel>(this HtmlHelper htmlHelper, Expression<Func<TModel, object>> expression)
        {
            return new HiddenBuilder<TModel>(htmlHelper, expression);
        }
    }

    public class HiddenBuilder<TModel> : HtmlInputElementBuilder<TModel>
    {
        internal HiddenBuilder(HtmlHelper htmlHelper, Expression<Func<TModel, object>> expression)
            : base(htmlHelper, expression)
        {
            // default
            this.value = expression.Compile()((TModel)htmlHelper.ViewData.Model);
        }

        protected override string BuildCore()
        {
            return this.htmlHelper.Hidden(htmlHelper.BuildBindingPath(this.expression), this.value, this.htmlAttributes).ToHtmlString();
        }
    }
}
